﻿#if NETSTANDARD2_0_OR_GREATER || NET5_0_OR_GREATER

using AutoCommunication.Enums;
using Microsoft.Extensions.Hosting;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace AutoCommunication.Web
{
    /// <summary>
    ///
    /// </summary>
    public class AutoService : BackgroundService
    {
        /// <summary>
        ///
        /// </summary>
        /// <param name="stoppingToken"></param>
        /// <returns></returns>
        protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            var dev = Auto.LoadByJson().Value;
            foreach (var item in dev)
            {
                item.Start(log, alarm, datachange);
            }
            return Task.CompletedTask;
        }

        private void datachange(Base.BaseVariable obj)
        {
            ;
        }

        private void alarm(Base.BaseVariable arg1, Base.AlarmEventArgs arg2)
        {
            ;
        }

        private void log(string name, Exception ex, AlarmLevel alarmLevel)
        {
            Console.WriteLine(name); ;
        }
    }
}

#endif